package com.ting.template.web.controller;

import com.ting.template.core.common.exception.AbeyException;
import com.ting.template.dal.dataobject.UserDO;
import com.ting.template.domainservice.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 雷霆 on 2017/12/22.
 *
 * Description：
 *
 * Modification History:
 *
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping(value="/user/*")
public class UserController {
	
	private static final Logger logger = Logger.getLogger(UserController.class);

	@Autowired
	private UserService userService;

/**
	 * 用户登录
	 * @return
	 */
	@RequestMapping(value="login.action")
	@ResponseBody
	public Map<String,Object> login( @RequestParam String userAccount, @RequestParam String passWord){

		Map<String,Object> map=new HashMap<String,Object>();
		String msg="";
		boolean flag=true;
		try{
			UserDO userDO=userService.login(userAccount,passWord);
			map.put("user", userDO);
			logger.info("登陆成功!");
		}catch(AbeyException e){
			msg=e.getMessage();
			flag=false;
		}catch(Exception e){
			logger.error(e.getMessage());
		}
		
		map.put("msg", msg);
		map.put("flag", flag);
		return map;
	}
	
	
	
	
	


}
